﻿using System;
using BorgExt;

namespace Borg.Desktop
{
    internal static class ConsoleLogger
    {
        internal static void OnLog(object sender, BorgExt.LogEventArgs args)
        {
            var foregroundColor = Console.ForegroundColor;
            var extension = sender as Extension;

            if (extension != null)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("[{0}:{1}]: ", extension.Id, extension.Name);
                Console.ForegroundColor = foregroundColor;
            }

            if (args.Type != LogType.Info)
                Console.ForegroundColor =
                    args.Type == LogType.Error
                        ? ConsoleColor.Red
                        : ConsoleColor.Yellow;

            Console.WriteLine(args.Message);
            Console.ForegroundColor = foregroundColor;
        }

        internal static void OnLog(object sender, LogType type, string message, params object[] args)
        {
            OnLog(sender, new BorgExt.LogEventArgs(type, string.Format(message, args)));
        }

        internal static void PrintLogo()
        {
            Console.WriteLine(BorgExt.Runtime.VersionInfo);
        }
    }
}
